package com.iafme.controller;

import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.operator.Contain;
import cn.zhxu.bs.operator.Equal;
import cn.zhxu.bs.util.MapUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.CertificateOrderReqDTO;
import com.iafme.dto.res.CertificateOrderResDTO;
import com.iafme.model.CertificateOrder;
import com.systemframework.util.SearchUtl;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author summer
 * @version 1.0
 * @date 2025/3/29 13:02
 */
@RestController
@RequestMapping(value = "/certificateOrder")
@AllArgsConstructor
public class CertificateOrderController {

    private final BeanSearcher beanSearcher;

    @PostMapping(value = "/lists")
    public Page<CertificateOrderResDTO> page(@RequestBody CertificateOrderReqDTO certificateOrderReqDTO) {
        Map<String, Object> build = MapUtils.builder().page(certificateOrderReqDTO.getPageNum()-1, certificateOrderReqDTO.getPageSize())
                .field(CertificateOrderResDTO::getName, certificateOrderReqDTO.getName()).op(Contain.class)
                .field(CertificateOrderResDTO::getIgAasId, certificateOrderReqDTO.getIgAasId()).op(Equal.class)
                .field(CertificateOrderResDTO::getStatus, certificateOrderReqDTO.getStatus()).op(Equal.class)
                .field(CertificateOrderResDTO::getOrderNo, certificateOrderReqDTO.getOrderNo()).op(Equal.class)
                .build();
        return SearchUtl.searchDataList(certificateOrderReqDTO.getPageNum(),certificateOrderReqDTO.getPageSize(),beanSearcher.search(CertificateOrderResDTO.class,build));

    }
}
